Casey Bralla The NerdWorld Report

J. R. Casey Bralla
377 Farmview Drive
East Earl, PA 17519
610-810-7716

Casey's eMail Address
Technology, Religion, Politics
and
The Mind-Body Dualism Problem

JRC-65 Computer

  1. Introduction and Design Objectives
  2. Clock Circuit

Tech Info


NerdWorld Computer Museum


Essays


Links




Site Hosted by
Vorlon Information Technologies


NerdWorld Logo

Entire site Copyright © 2024 by J. R. Casey Bralla
(except for obvious external works).
All rights reserved.

NOTE: If you link to this site, or otherwise find it useful, please send a brief note to the author.

Casey's eMail Address

Thank you!

Raspberry Pi Clock

May 29, 2025
Raspberry Pi Clock

You probably have a bunch of old Raspberry Pis lying around. You probably also have a bunch of old LCD monitors sitting in a closet gathering dust. This is a nice, simple way to put them to good use as a digital clock that automatically sets itself via the internet.


Raspberry Pi Mount

The Raspberry Pi is mounted to the back of LCD stand. I just drilled a few holes in the back side of the stand, added a few old bits of plastic for a spacer, and screwed the Pi to the stand. The I neatly tied up the HDMI cable from the PI to the input of the monitor. I used an old Dell P170 monitor I had lying around. Of course, you can use almost any type of Monitor. The Dell did not have an HDMI input, so I needed to add a DVI to HDMI adapter which can be had for $10-$20 if you don't already own one.

The Pi does NOT have to be a current model. The software required to run the clock is a simple python script. You can also use one of the numerous Pi equivalents; I'm using and Odroid I bought in 2016. You can run just about any Pi-compatible Operating Systems. I'm using the Ubuntu focal distribution, but any Pi OS should work fine.


Raspberry Pi Mount

Raspberry Pi Mount

Raspberry Pi in Use


Software


There are several software settings and the clock program itself which must be added to the Pi.

Firstly, the Pi needs to boot to X. I did this by adding this line to /etc/crontab:

    @reboot root startx
  


Screen blanking also needs to be prevented. Add these lines to /root/.xinitrc:

    xset s noblank
    xset s off
    xset -dpms
  


To ensure the clock is always accurate, I run the NTP routine every hour. I added this lines to /etc/crontab:

    1 *     * * * root ntpdate
  


Finally, the clock program itself must be started from /root/.xinitrc when X starts

    /home/clock/DigitalClock.py
  


Optionally, I like to reboot the computer every night because it occasionally goes off-line. I added this line to /etc/crontab to reboot at 3:00 AM every night:

    0 3     * * * root /sbin/reboot
  



Here is the code for the clock in python. It can also be downloaded here.

#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# DigitalClock.py
#
#
#  Display an nice looking digital clock for general use
#   Can be used as a dedicated clock on old Monitors with Raspberry Pi
#
#


Version = "1.1"
Author  = "J R Casey Bralla"
Program = "DigitalClock.py"



# Import some standard python modules
import os               # misc operating system calls.
import sys              # More misc operating system calls
import datetime         # Time & Date functions
import tkinter          # Screen manipulation and information
from tkinter import ttk # TK-Intger themed widgets



# Get the command line arguments
CommandLineArguments = sys.argv[1:]
# print ( CommandLineArguments )

# CommandLineArgument = ""

if len( CommandLineArguments ) > 0:
    #
    # show help
    #
    #
    print ( )
    print ( "Program"  + Program )
    print ( )
    print ( "Version " + Version )
    print ( "     by " + Author )
    print ( )
    print ( "Nice Digital Clock for general display" )
    print ( )
    print ( 'Usage: "' + Program + ' --help or -h for help"' )
    print ( )
    print ( )
    print ( )
    sys.exit(0)
    #








# Set some Variables
#
#
RPiCompositeVideo  = "Yes"    # Running on a with minimal software requires some special handling


WindowWidth  = 720  # Default for composite video on Raspberry Pi
WindowHeight = 480

#
TimeSize        = int( WindowWidth * (72/96) / 10 )
DayOfWeekSize   = int( WindowWidth * (72/96) / 20 )
LongDateSize    = int( WindowWidth * (72/96) / 15 )
ISODateSize     = int( WindowWidth * (72/96) / 25 )
#


Screen_Color    = "Black"   # Background color for the screen
Time_Color      = "White"   # Font Color for Time
DayOfWeek_Color = "Yellow"  # Font Color for Day of Week
LongDate_Color  = "Yellow"  # Font Color for Long Date
ISODate_Color   = "Yellow"  # Font Color for ISO Date





### Create the Window ###
### Create the Window ###
### Create the Window ###
#
#
#
MainWindow = tkinter.Tk()
MainWindow.title("NerdWorld Digital Clock" )
MainWindow.configure( bg="black" )
MainWindow.geometry( str(WindowWidth) + "x" + str(WindowHeight) )
MainWindow.attributes( '-topmost', True )   # Always on top

if RPiCompositeVideo != "Yes": MainWindow.attributes( '-zoomed',  True )   # Full screen window






### Function which acts as the main loop that updats the Time & Date ###
### Function which acts as the main loop that updats the Time & Date ###
### Function which acts as the main loop that updats the Time & Date ###
#
#
#
def update():
    #
    #
    ### Get the Time and Date and format it ###
    #
    TimeNow     = datetime.datetime.now()
    #
    Time        = TimeNow.strftime("%-I:%M:%S %p")
    DayOfWeek   = TimeNow.strftime("%A")
    LongDate    = TimeNow.strftime("%B %-d, %Y")
    ISODate     = TimeNow.strftime("%Y-%m-%d")
    #
    #
    # Set the font sizes based on the window size
    #
    TimeSize        = 24        # Font Size for Time
    DayOfWeekSize   = 18        # Font Size for Day of Week
    LongDateSize    = 18        # Font Size for Long Date
    ISODateSize     = 12        # Font Size for ISO Date
    #
    if RPiCompositeVideo != "Yes":        # The Pi doesn't maximize properly
        #
        #
        WindowWidth = MainWindow.winfo_width()
        #
        #
    else:
        #
        WindowWidth = 720
        #
    #
    # print (WindowWidth)  #
    #
    TimeSize        = int( WindowWidth * (72/96) / 10 )
    DayOfWeekSize   = int( WindowWidth * (72/96) / 20 )
    LongDateSize    = int( WindowWidth * (72/96) / 15 )
    ISODateSize     = int( WindowWidth * (72/96) / 25 )
    #
    #
    #
    #
    ### Display the Time ###
    ### Display the Time ###
    ### Display the Time ###
    #
    TimeLabel.config(       text=Time,      font=("Helvetica", TimeSize) )
    DayOfWeekLabel.config(  text=DayOfWeek, font=("Helvetica", DayOfWeekSize) )
    LongDateLabel.config(   text=LongDate,  font=("Helvetica", LongDateSize) )
    ISODateLabel.config(    text=ISODate,   font=("Helvetica", ISODateSize) )
    BlankLabel.config(      text=" ")
    #
    #
    # Force an update after waiting milliseconds
    #
    TimeLabel.after(100, update)    # Updates every tenth of a second.  (No more than .1 seconds error)
    #
    #
    #






### Define the labels ###
### Define the labels ###
### Define the labels ###
#
#
#
TimeLabel = ttk.Label(
    MainWindow,
    text="*",
    foreground=Time_Color,
    background="black"
    )
#
DayOfWeekLabel = ttk.Label(
    MainWindow,
    text="*",
    foreground=DayOfWeek_Color,
    background="black"
    )
#
LongDateLabel = ttk.Label(
    MainWindow,
    text="*",
    foreground=LongDate_Color,
    background="black"
    )
#
#
#
ISODateLabel = ttk.Label(
    MainWindow,
    text="*",
    foreground=ISODate_Color,
    background="black"
    )
#
BlankLabel = ttk.Label(
    MainWindow,
    text="*",
    font=("Helvetica", 10),
    foreground="white",
    background="black"
    )








### Pack the labels onto the window
#
#
TimeLabel.pack(     side=tkinter.TOP,            expand=True)
DayOfWeekLabel.pack(side=tkinter.TOP, ipady = 5, expand=False)
LongDateLabel.pack( side=tkinter.TOP, ipady = 5, expand=False)
ISODateLabel.pack(  side=tkinter.TOP, ipady=5,   expand=False)
BlankLabel.pack(    side=tkinter.TOP, ipady=5,   expand=True)
#
#
#



### Run the fucntion to Update the labels ###
#
#
update()





### Obligatory TKInter routine to keep window open

MainWindow.mainloop()